define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'xiluhouse/appoint/followlog/index' + location.search,
                    add_url: 'xiluhouse/appoint/followlog/add',
                    edit_url: 'xiluhouse/appoint/followlog/edit',
                    del_url: 'xiluhouse/appoint/followlog/del',
                    multi_url: 'xiluhouse/appoint/followlog/multi',

                    user_url: 'xiluhouse/user/user/index',

                    table: 'follow_log',
                }
            });

            var table = $("#table");
            table.on('post-common-search.bs.table', function (event, table) {
                var form = $("form", table.$commonsearch);
                $("input[name='user_id']", form).addClass("selectpage").data("source", $.fn.bootstrapTable.defaults.extend.user_url).data("primaryKey", "id").data("field", "mobile");
                $("input[name='broker_user_id']", form).addClass("selectpage").data("source", $.fn.bootstrapTable.defaults.extend.user_url).data("primaryKey", "id").data("field", "mobile").data("params", function (obj) {
                    return {custom: {'userprofile.is_broker': 2}};
                });
            })
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                //启用固定列
                fixedColumns: true,
                //固定右侧列数
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),sortable:true},
                        {field: 'user_id', title: __('User_id'),formatter: function (value, row, index) {
                            if(row.user_id>0){
                                var html='';
                                var url =$.fn.bootstrapTable.defaults.extend.user_url+ "?id=" + row.user_id;
                                html+='<a  href="' + url + '" class="bg-info btn-dialog" title="查看关联信息"> 【'+ row.user_id +'】'+row.user.nickname+'<br/>'+row.user.mobile+' </a>';
                                return html;
                            }else{
                                return '-';
                            }
                        }
                        },
                        {field: 'broker_user_id', title: __('Broker_user_id'),formatter: function (value, row, index) {
                            if(row.broker_user_id>0){
                                var html='';
                                var url =$.fn.bootstrapTable.defaults.extend.user_url+ "?id=" + row.broker_user_id;
                                html+='<a  href="' + url + '" class="bg-info btn-dialog" title="查看关联信息"> 【'+ row.broker_user_id +'】'+row.broker.nickname+'<br/>'+row.broker.mobile+' </a>';
                                return html;
                            }else{
                                return '-';
                            }
                        }
                        },
                        {field: 'house_state', title: __('House_state'), searchList: {"0":__('House_state 0'),"1":__('House_state 1'),"2":__('House_state 2'),"3":__('House_state 3'),"4":__('House_state 4'),"5":__('House_state 5'),"6":__('House_state 6')}, formatter: Table.api.formatter.normal},
                        //{field: 'audit_state', title: __('Audit_state'), searchList: {"1":__('Audit_state 1'),"2":__('Audit_state 2'),"3":__('Audit_state 3'),"4":__('Audit_state 4')}, formatter: Table.api.formatter.normal},
                        {field: 'name', title: __('Name')},
                        {field: 'discription', title: __('Discription'), operate: 'LIKE',visible:false},
                        {field: 'dissatisfaction', title: __('Dissatisfaction'), operate: 'LIKE',visible:false},
                        {field: 'err_msg', title: __('Err_msg'), operate: 'LIKE',visible:false},
                        {field: 'money', title: __('Money'), operate:'BETWEEN',visible:false},
                        {field: 'get_money', title: __('Get_money'), operate:'BETWEEN',visible:false},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        //{field: 'checktime', title: __('Checktime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'status', title: __('Status'), searchList: {"normal":__('Status normal'),"hidden":__('Status hidden')}, formatter: Table.api.formatter.status},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});